mcurrentsens 2.2.0
Loading...
Searching...
No Matches
mcurrentsens


mCurrent Sens Click

mCurrent Sens Click demo application is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, the demo is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.


Click Library

  • Author : Stefan Filipovic
  • Date : Apr 2026.
  • Type : SPI type

Software Support

Example Description

This example demonstrates the use of mCurrent Sens Click for measuring voltage, current, and temperature on two independent channels.

Example Libraries

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.mCurrentSens

Example Key Functions

Application Init

Initializes communication, configures the device, optionally performs calibration, and loads calibration data from EEPROM. ADC oversampling ratio is set for faster runtime measurements.

void application_init ( void )
{
log_cfg_t log_cfg;
mcurrentsens_cfg_t mcurrentsens_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
mcurrentsens_cfg_setup( &mcurrentsens_cfg );
if ( SPI_MASTER_ERROR == mcurrentsens_init( &mcurrentsens, &mcurrentsens_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( MCURRENTSENS_ERROR == mcurrentsens_default_cfg ( &mcurrentsens ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
#if ENABLE_CALIBRATION
if ( MCURRENTSENS_OK == mcurrentsens_calibrate_device ( &mcurrentsens ) )
{
log_printf( &logger, " Device calibration success\r\n" );
}
else
{
log_error( &logger, " Device calibration" );
for ( ; ; );
}
#endif
if ( MCURRENTSENS_OK == mcurrentsens_fetch_calib ( &mcurrentsens ) )
{
log_printf( &logger, " Calibration data read from EEPROM\r\n" );
}
else
{
log_error( &logger, " Calibration fetch - No communication with EEPROM or EEPROM is empty" );
for ( ; ; );
}
/* Reduce OSR after calibration for faster runtime measurements. */
log_info( &logger, " Application Task " );
}
#define MCURRENTSENS_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition mcurrentsens.h:382
#define MCURRENTSENS_CONFIG1_OSR_256
Definition mcurrentsens.h:158
err_t mcurrentsens_set_osr(mcurrentsens_t *ctx, uint8_t osr)
mCurrent Sens set OSR function.
void application_init(void)
Definition main.c:59
#define MIKROBUS_POSITION_MCURRENTSENS
Definition main.c:28
@ MCURRENTSENS_OK
Definition mcurrentsens.h:464
@ MCURRENTSENS_ERROR
Definition mcurrentsens.h:465

Application Task

Reads and logs voltage, current, and temperature values continuously.

void application_task ( void )
{
float ch1_voltage_mv = 0;
float ch1_current_ma = 0;
float ch2_voltage_mv = 0;
float ch2_current_ma = 0;
float temperature = 0;
if ( MCURRENTSENS_OK == mcurrentsens_read_ch1_voltage( &mcurrentsens, &ch1_voltage_mv ) )
{
log_printf( &logger, " CH1 voltage : %.1f mV\r\n", ch1_voltage_mv );
}
else
{
log_printf( &logger, " CH1 voltage read error\r\n" );
}
if ( MCURRENTSENS_OK == mcurrentsens_read_ch1_current( &mcurrentsens, &ch1_current_ma ) )
{
log_printf( &logger, " CH1 current : %.2f mA\r\n", ch1_current_ma );
}
else
{
log_printf( &logger, " CH1 current read error\r\n" );
}
if ( MCURRENTSENS_OK == mcurrentsens_read_ch2_voltage( &mcurrentsens, &ch2_voltage_mv ) )
{
log_printf( &logger, " CH2 voltage : %.1f mV\r\n", ch2_voltage_mv );
}
else
{
log_printf( &logger, " CH2 voltage read error\r\n" );
}
if ( MCURRENTSENS_OK == mcurrentsens_read_ch2_current( &mcurrentsens, &ch2_current_ma ) )
{
log_printf( &logger, " CH2 current : %.2f mA\r\n", ch2_current_ma );
}
else
{
log_printf( &logger, " CH2 current read error\r\n" );
}
if ( MCURRENTSENS_OK == mcurrentsens_read_temperature( &mcurrentsens, &temperature ) )
{
log_printf( &logger, " Temperature : %.2f degC\r\n", temperature );
}
else
{
log_printf( &logger, " Temperature read error\r\n" );
}
log_printf( &logger, "-----------------------------\r\n" );
Delay_ms( 1000 );
}
err_t mcurrentsens_read_temperature(mcurrentsens_t *ctx, float *data_out)
mCurrent Sens read temperature function.
err_t mcurrentsens_read_ch2_current(mcurrentsens_t *ctx, float *data_out)
mCurrent Sens read channel 2 current function.
err_t mcurrentsens_read_ch2_voltage(mcurrentsens_t *ctx, float *data_out)
mCurrent Sens read channel 2 voltage function.
void application_task(void)
Definition main.c:120

Application Output

This Click board can be interfaced and monitored in two ways:

  • Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.
  • UART Terminal - Monitor data via the UART Terminal using a USB to UART converter. For detailed instructions, check out this tutorial.

Additional Notes and Information

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.